package t327.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import t327.pojo.*;
import t327.pojo.font.LuiTableEntity;
import t327.pojo.until.Result;
import t327.pojo.views.ProductionPlanOrderSizeDepartmentView;
import t327.pojo.views.StoreAreaWarehouseView;
import t327.service.iter.IProductService;

import java.util.HashMap;
import java.util.List;
@Controller
@RequestMapping("Product")
public class ProductQuaController {
    @Autowired
    private IProductService iProductService;
    @RequestMapping("getQualityAll")
    @ResponseBody
    public LuiTableEntity getQualityAll(@RequestParam(value = "page") Integer pageNum, @RequestParam(value = "limit")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        LuiTableEntity luiTableEntity = new LuiTableEntity<ProductionPlanOrderSizeDepartmentView>();
        PageInfo<ProductionPlanOrderSizeDepartmentView> classProductViewPageInfo = new PageInfo<ProductionPlanOrderSizeDepartmentView>(iProductService.getProQuaAll());
        List<ProductionPlanOrderSizeDepartmentView> products = classProductViewPageInfo.getList();
        long total = classProductViewPageInfo.getTotal();
        if(products!=null&&products.size()>0){
            luiTableEntity.setCode("0");
            luiTableEntity.setMsg("查询成功");
            luiTableEntity.setCount(total);
            luiTableEntity.setData(products);
        }else{
            luiTableEntity.setCode("2032");
            luiTableEntity.setMsg("查询失败");
        }
        System.out.println("1");
        System.out.println(products);
        return   luiTableEntity;
    }
    @RequestMapping("deleteByProductionId")
    @ResponseBody
    public int deleteByProductionId(Long productionPlanId) {
        return iProductService.deleteByLogicDel(productionPlanId);
    }
    @RequestMapping("addProQuaAll")
    @ResponseBody
    public int addProQuaAll(@RequestBody Store store) {
        return iProductService.addProQuaAll(store);
    }

    @RequestMapping("addProQductPlan")
    @ResponseBody
    public int addProQductPlan(@RequestBody ProductionPlan productionPlan) {
        return iProductService.addProQductPlan(productionPlan);
    }
    @RequestMapping("getSubmissionAll")
    @ResponseBody
    public List<Submission> getSubmissionAll() {
        return iProductService.getSubmissionAll();
    }
    @RequestMapping("toStoreAreaWarehouseView")
    @ResponseBody
    public List<StoreAreaWarehouseView> toStoreAreaWarehouseView() {
        return iProductService.getStoreAreaWarehouseView();
    }
    @RequestMapping("StoreAreaWarehouseViewAll")
    @ResponseBody
    public LuiTableEntity StoreAreaWarehouseViewAll(@RequestParam(value = "page") Integer pageNum, @RequestParam(value = "limit")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        LuiTableEntity luiTableEntity = new LuiTableEntity<StoreAreaWarehouseView>();
        PageInfo<StoreAreaWarehouseView> classProductViewPageInfo = new PageInfo<StoreAreaWarehouseView>(iProductService.togetStoreAreaWarehouseViewAll());
        List<StoreAreaWarehouseView> products = classProductViewPageInfo.getList();
        long total = classProductViewPageInfo.getTotal();
        if(products!=null&&products.size()>0){
            luiTableEntity.setCode("0");
            luiTableEntity.setMsg("查询成功");
            luiTableEntity.setCount(total);
            luiTableEntity.setData(products);
        }else{
            luiTableEntity.setCode("2032");
            luiTableEntity.setMsg("查询失败");
        }
        System.out.println("1");
        System.out.println(products);
        return   luiTableEntity;
    }
    public boolean isNumeric(String input) {
        try {
            Long.parseLong(input);  // 尝试将输入解析为整数
            // 或
            // Double.parseDouble(input);  // 尝试将输入解析为浮点数
            return true;  // 解析成功，输入为数字
        } catch (NumberFormatException e) {
            return false;  // 解析失败，输入不是数字
        }
    }
    @RequestMapping("toaddstoreAreaWare")
    @ResponseBody
    public Result toaddstoreAreaWare(@RequestBody Store store) {
        Long productionCount=store.getProductionCount();
        Long countStatus=store.getCountStatus();

        if(productionCount==null & countStatus==-1) {
            return new Result(310,"请填写全部，不能有空哦",false,null);
        }else if(!isNumeric(productionCount.toString())){
            return new Result(311,"请填写数字，不能填写其他内容",false,null);
        } else if(productionCount<0||countStatus<0){
            return new Result(312,"请填写内容大于0",false,null);
        } else {
            int i=iProductService.addstoreAreaWare(store);
            if(i>0){
                return new Result(313,"保存成功",false,null);
            } else {
                return new Result(315,"添加失败",false,null);
            }
        }
    }
    @RequestMapping("queryOrderForm")
    @ResponseBody
    public List<OrderForm> queryOrderForm() {
        return iProductService.queryOrderForm();
    }
    @RequestMapping("queryProductDetail")
    @ResponseBody
    public List<ProductDetail> queryProductDetail() {
        return iProductService.queryProductDetail();
    }
    @RequestMapping("queryStore")
    @ResponseBody
    public List<Store> queryStore() {
        return iProductService.queryStore();
    }
}
